package com.liu.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * ribbon
 * @author LIU
 * @version 1.0
 * @description: nacos-discovery默认依赖ribbon
 * @date 2023/6/18 12:56
 */
@SpringBootApplication
public class OrderRibbonApplication {
    public static void main(String[] args) {
        SpringApplication.run(OrderRibbonApplication.class, args);
    }


    @Bean
    @LoadBalanced/* 增加负载均衡能力 */
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
            return restTemplateBuilder
                    //请求处理超时时间
                    .setReadTimeout(Duration.ofSeconds(2L))
                    //连接超时时间
                    .setConnectTimeout(Duration.ofSeconds(2L))
                    .build();
    }
}
